
 
package galleryviewer;
 
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.paint.Color;
import javafx.scene.input.*;
import javafx.scene.text.*;

package function closePopups(e:MouseEvent):Void {
	//if(GalleryFloor.openedPopups!=null) {
	    for(p:PopUp in GalleryFloor.openedPopups) {
			//delete p from GalleryFloor.floors[GalleryFloor.currentFloor].galleryContent;
			Effects.fadeOut(p);
	    }
    //}
}

/**
 * @author SiMet
 */
public class PopUp extends CustomNode {
     
    override var blocksMouse = true;    
    public var wysokosc : Integer;
    public var szerokosc : Integer;
    public var clickX : Double = 0;
    public var clickY : Double = 0;
    public var maxX : Double;
    public var maxY : Double;
    public var text : String; 
    
    override var onMouseClicked = closePopups;
    
    var zlyX : Boolean = false;
    var zlyY : Boolean = false;
    
	public override function create(): Node {
        if(clickY<wysokosc*1.1){
			zlyY = true;
		}
        if(clickX>maxX-szerokosc*0.9){
            zlyX = true;           
        }
        var strzalka = Polygon{points : [szerokosc*0.2,wysokosc*1.2,szerokosc*0.15,wysokosc*1.1,szerokosc*0.25,wysokosc*1.1]};
        var shape : ShapeIntersect = ShapeIntersect{                  
	         a : [Rectangle{x: 0, y: 0, width: szerokosc*1.2, height: wysokosc*1.2}];
	         b : [Rectangle{x: szerokosc*0.1, y: wysokosc*0.1, width: szerokosc, height: wysokosc, arcWidth: 10, arcHeight: 10} ];
	         fill : Color.web("#202020");
	         stroke : Color.web("#202020");
	         strokeWidth : 0;
	     }
               
         var napis : Text = Text{
	         content: text;
	         wrappingWidth: szerokosc*0.8;
	         translateY: 20;
	         translateX: -szerokosc*0.9;
             fill: Color.web("#ffffff");

		 }
         if(zlyX){
            napis.translateX += szerokosc*0.95; 	      
         }
	                       	            
         insert strzalka into shape.b;
         shape.translateX = clickX-0.2*szerokosc;
         shape.translateY = clickY-wysokosc*1.2;
         var tresc : Group = Group {
              content : [
                napis
              ];
              translateX : clickX+szerokosc*0.85;
              translateY : clickY-wysokosc*1.05;
         }         
         
         if(zlyY){
            shape.scaleY = -1;
            shape.translateY +=wysokosc*1.1;
            tresc.translateY +=wysokosc*1.2;
         }
         if(zlyX){
            shape.scaleX = -1;
            shape.translateX -=szerokosc*0.8;
            tresc.translateX -=szerokosc*1.7;             
         }
         
         Effects.fadeIn(this);
         Main.popupCounter.playFromStart();
         
	   return Group { content: [ shape, tresc ] };
	}
}